<template>
  <div class="app-container">
    <el-form :model="queryParams" ref="queryForm" size="small" :inline="true" v-show="showSearch" label-width="68px">
      <el-form-item label="微博UID" prop="weiboUserId">
        <el-input
          v-model="queryParams.weiboUserId"
          placeholder="请输入微博UID"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="昵称" prop="nickname">
        <el-input
          v-model="queryParams.nickname"
          placeholder="请输入昵称"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="性别" prop="gender">
        <el-select v-model="queryParams.gender" placeholder="请选择性别" clearable>
          <el-option
            v-for="dict in dict.type.kiku_base_info_sex2"
            :key="dict.value"
            :label="dict.label"
            :value="dict.value"
          />
        </el-select>
      </el-form-item>
      <el-form-item label="粉丝数" prop="fansCount">
        <el-input
          v-model="queryParams.fansCount"
          placeholder="请输入粉丝数"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="关注数" prop="followCount">
        <el-input
          v-model="queryParams.followCount"
          placeholder="请输入关注数"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="微博数" prop="weiboCount">
        <el-input
          v-model="queryParams.weiboCount"
          placeholder="请输入微博数"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="转评赞" prop="repostCommentLike">
        <el-input
          v-model="queryParams.repostCommentLike"
          placeholder="请输入转评赞"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="评论量" prop="commentCount">
        <el-input
          v-model="queryParams.commentCount"
          placeholder="请输入评论量"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="点赞量" prop="likeCount">
        <el-input
          v-model="queryParams.likeCount"
          placeholder="请输入点赞量"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="转发量" prop="repostCount">
        <el-input
          v-model="queryParams.repostCount"
          placeholder="请输入转发量"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item>
        <el-button type="primary" icon="el-icon-search" size="mini" @click="handleQuery">搜索</el-button>
        <el-button icon="el-icon-refresh" size="mini" @click="resetQuery">重置</el-button>
      </el-form-item>
    </el-form>

    <el-row :gutter="10" class="mb8">
      <el-col :span="1.5">
        <el-button
          type="warning"
          plain
          icon="el-icon-download"
          size="mini"
          @click="handleExport"
          v-hasPermi="['kiku:sisterDetails:export']"
        >导出</el-button>
      </el-col>
      <el-col :span="1.5">
        <el-button
          type="success"
          plain
          icon="el-icon-edit"
          size="mini"
          @click="allSynchronous"
          v-hasPermi="['kiku:sisterDetails:edit']"
        >同步站姐信息</el-button>
      </el-col>
      <right-toolbar :showSearch.sync="showSearch" @queryTable="getList"></right-toolbar>
    </el-row>

    <el-table v-loading="loading" :data="sisterDetailsList" @selection-change="handleSelectionChange">
      <el-table-column label="微博UID" align="center" prop="weiboUserId" width="100" />
      <el-table-column label="昵称" align="center" prop="nickname" width="150" />
      <el-table-column label="性别" align="center" prop="gender">
        <template slot-scope="scope">
          <dict-tag :options="dict.type.kiku_base_info_sex2" :value="scope.row.gender"/>
        </template>
      </el-table-column>
      <el-table-column label="粉丝数" align="center" prop="fansCount" />
      <el-table-column label="关注数" align="center" prop="followCount" />
      <el-table-column label="微博数" align="center" prop="weiboCount" />
      <el-table-column label="转评赞" align="center" prop="repostCommentLike" />
      <el-table-column label="评论量" align="center" prop="commentCount" />
      <el-table-column label="点赞量" align="center" prop="likeCount" />
      <el-table-column label="转发量" align="center" prop="repostCount" />
      <el-table-column label="介绍" align="center" prop="description" width="120" >
        <template slot-scope="scope">
          <div class="cell-content">
            <el-tooltip :content="scope.row.description" placement="top" effect="dark" >
              <span class="content-text">{{ scope.row.description }}</span>
            </el-tooltip>
            <br>
            <el-button
              type="text"
              icon="el-icon-copy-document"
              @click="copyText(scope.row.description)"
              style="margin-left: 5px;"
            />
          </div>
        </template>
      </el-table-column>
      <el-table-column label="备注" align="center" prop="remark" />
      <el-table-column label="操作" align="center" class-name="small-padding fixed-width">
        <template slot-scope="scope">
          <el-button
            size="mini"
            type="text"
            icon="el-icon-view"
            @click="handleUpdate(scope.row)"
          >快捷进入</el-button>
        </template>
      </el-table-column>
    </el-table>

    <pagination
      v-show="total>0"
      :total="total"
      :page.sync="queryParams.pageNum"
      :limit.sync="queryParams.pageSize"
      @pagination="getList"
    />

    <!-- 添加或修改小鞠站姐详细信息对话框 -->
    <el-dialog :title="title" :visible.sync="open" width="500px" append-to-body>
      <el-form ref="form" :model="form" :rules="rules" label-width="80px">
        <el-form-item label="微博UID" prop="weiboUserId">
          <el-input v-model="form.weiboUserId" placeholder="请输入微博UID" />
        </el-form-item>
        <el-form-item label="昵称" prop="nickname">
          <el-input v-model="form.nickname" placeholder="请输入昵称" />
        </el-form-item>
        <el-form-item label="性别" prop="gender">
          <el-select v-model="form.gender" placeholder="请选择性别">
            <el-option
              v-for="dict in dict.type.kiku_base_info_sex2"
              :key="dict.value"
              :label="dict.label"
              :value="parseInt(dict.value)"
            ></el-option>
          </el-select>
        </el-form-item>
        <el-form-item label="粉丝数" prop="fansCount">
          <el-input v-model="form.fansCount" placeholder="请输入粉丝数" />
        </el-form-item>
        <el-form-item label="关注数" prop="followCount">
          <el-input v-model="form.followCount" placeholder="请输入关注数" />
        </el-form-item>
        <el-form-item label="微博数" prop="weiboCount">
          <el-input v-model="form.weiboCount" placeholder="请输入微博数" />
        </el-form-item>
        <el-form-item label="转评赞" prop="repostCommentLike">
          <el-input v-model="form.repostCommentLike" placeholder="请输入转评赞" />
        </el-form-item>
        <el-form-item label="评论量" prop="commentCount">
          <el-input v-model="form.commentCount" placeholder="请输入评论量" />
        </el-form-item>
        <el-form-item label="点赞量" prop="likeCount">
          <el-input v-model="form.likeCount" placeholder="请输入点赞量" />
        </el-form-item>
        <el-form-item label="转发量" prop="repostCount">
          <el-input v-model="form.repostCount" placeholder="请输入转发量" />
        </el-form-item>
        <el-form-item label="介绍" prop="description">
          <el-input v-model="form.description" type="textarea" placeholder="请输入内容" />
        </el-form-item>
        <el-form-item label="备注" prop="remark">
          <el-input v-model="form.remark" type="textarea" placeholder="请输入内容" />
        </el-form-item>
      </el-form>
      <div slot="footer" class="dialog-footer">
        <el-button type="primary" @click="submitForm">确 定</el-button>
        <el-button @click="cancel">取 消</el-button>
      </div>
    </el-dialog>
  </div>
</template>

<script>
import {
  listSisterDetails,
  getSisterDetails,
  delSisterDetails,
  addSisterDetails,
  updateSisterDetails,
  allSynchronousKikuStationSisterDetails
} from "@/api/kiku/sisterDetails";

export default {
  name: "SisterDetails",
  dicts: ['kiku_base_info_sex2'],
  data() {
    return {
      // 遮罩层
      loading: true,
      // 选中数组
      ids: [],
      // 非单个禁用
      single: true,
      // 非多个禁用
      multiple: true,
      // 显示搜索条件
      showSearch: true,
      // 总条数
      total: 0,
      // 小鞠站姐详细信息表格数据
      sisterDetailsList: [],
      // 弹出层标题
      title: "",
      // 是否显示弹出层
      open: false,
      // 查询参数
      queryParams: {
        pageNum: 1,
        pageSize: 10,
        weiboUserId: null,
        nickname: null,
        gender: null,
        fansCount: null,
        followCount: null,
        weiboCount: null,
        repostCommentLike: null,
        commentCount: null,
        likeCount: null,
        repostCount: null,
        description: null,
      },
      // 表单参数
      form: {},
      // 表单校验
      rules: {
        weiboUserId: [
          { required: true, message: "微博UID不能为空", trigger: "blur" }
        ],
        gender: [
          { required: true, message: "性别不能为空", trigger: "change" }
        ],
        fansCount: [
          { required: true, message: "粉丝数不能为空", trigger: "blur" }
        ],
        followCount: [
          { required: true, message: "关注数不能为空", trigger: "blur" }
        ],
        weiboCount: [
          { required: true, message: "微博数不能为空", trigger: "blur" }
        ],
        repostCommentLike: [
          { required: true, message: "转评赞不能为空", trigger: "blur" }
        ],
        commentCount: [
          { required: true, message: "评论量不能为空", trigger: "blur" }
        ],
        likeCount: [
          { required: true, message: "点赞量不能为空", trigger: "blur" }
        ],
        repostCount: [
          { required: true, message: "转发量不能为空", trigger: "blur" }
        ],
      }
    };
  },
  created() {
    this.getList();
  },
  methods: {
    /**复制功能*/
    copyText(content) {
      navigator.clipboard.writeText(content).then(() => {
        this.$message.success('内容已复制到剪贴板！');
      }).catch(err => {
        this.$message.error('复制失败，请重试！');
      });
    },
    /** 查询小鞠站姐详细信息列表 */
    getList() {
      this.loading = true;
      listSisterDetails(this.queryParams).then(response => {
        this.sisterDetailsList = response.rows;
        this.total = response.total;
        this.loading = false;
      });
    },
    // 取消按钮
    cancel() {
      this.open = false;
      this.reset();
    },
    // 表单重置
    reset() {
      this.form = {
        id: null,
        weiboUserId: null,
        nickname: null,
        gender: null,
        fansCount: null,
        followCount: null,
        weiboCount: null,
        repostCommentLike: null,
        commentCount: null,
        likeCount: null,
        repostCount: null,
        description: null,
        createBy: null,
        createTime: null,
        updateBy: null,
        updateTime: null,
        remark: null
      };
      this.resetForm("form");
    },
    /** 搜索按钮操作 */
    handleQuery() {
      this.queryParams.pageNum = 1;
      this.getList();
    },
    /** 重置按钮操作 */
    resetQuery() {
      this.resetForm("queryForm");
      this.handleQuery();
    },
    // 多选框选中数据
    handleSelectionChange(selection) {
      this.ids = selection.map(item => item.id)
      this.single = selection.length!==1
      this.multiple = !selection.length
    },
    /** 新增按钮操作 */
    handleAdd() {
      this.reset();
      this.open = true;
      this.title = "添加小鞠站姐详细信息";
    },
    /** 修改按钮操作 */
    handleUpdate(row) {
      const uid = row.weiboUserId;
      const weiboUrl = "https://weibo.com/u/"+uid;
      window.open(weiboUrl, '_blank'); // 新标签页打开
    },
    /** 提交按钮 */
    submitForm() {
      this.$refs["form"].validate(valid => {
        if (valid) {
          if (this.form.id != null) {
            updateSisterDetails(this.form).then(response => {
              this.$modal.msgSuccess("修改成功");
              this.open = false;
              this.getList();
            });
          } else {
            addSisterDetails(this.form).then(response => {
              this.$modal.msgSuccess("新增成功");
              this.open = false;
              this.getList();
            });
          }
        }
      });
    },
    /** 删除按钮操作 */
    handleDelete(row) {
      const ids = row.id || this.ids;
      this.$modal.confirm('是否确认删除小鞠站姐详细信息编号为"' + ids + '"的数据项？').then(function() {
        return delSisterDetails(ids);
      }).then(() => {
        this.getList();
        this.$modal.msgSuccess("删除成功");
      }).catch(() => {});
    },
    /** 导出按钮操作 */
    handleExport() {
      this.download('kiku/sisterDetails/export', {
        ...this.queryParams
      }, `sisterDetails_${new Date().getTime()}.xlsx`)
    },
    /** 同步站姐信息 */
    allSynchronous(){
      this.$modal.confirm('是否确认同步小鞠站姐详细信息？').then(function() {
        return allSynchronousKikuStationSisterDetails();
      }).then(() => {
        this.getList();
        this.$modal.msgSuccess("同步成功");
      }).catch(() => {});
    },
  }
};
</script>
<style scoped>
.content-text {
  display: inline-block;
  max-width: 100%;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  vertical-align: top;
}
</style>
